package net.realsee.controller.wcs.intf;

import cn.dev33.satoken.annotation.SaCheckPermission;
import lombok.RequiredArgsConstructor;
import net.realsee.common.annotation.Log;
import net.realsee.common.annotation.RepeatSubmit;
import net.realsee.common.enums.BusinessType;
import net.realsee.common.utils.poi.ExcelUtil;
import net.realsee.domain.wcs.intf.bo.WcsIntfOutlogBo;
import net.realsee.domain.wcs.intf.vo.WcsIntfOutlogVo;
import net.realsee.framework.core.controller.BaseController;
import net.realsee.framework.core.domain.PageQuery;
import net.realsee.framework.core.domain.R;
import net.realsee.framework.core.page.TableDataInfo;
import net.realsee.framework.core.validate.AddGroup;
import net.realsee.framework.core.validate.EditGroup;
import net.realsee.service.wcs.intf.IWcsIntfOutlogService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.Arrays;
import java.util.List;

/**
 * Outbound接口日志
 *
 * @author realsee
 * @date 2023-08-11
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/wcs/intfOutlog")
public class WcsIntfOutlogController extends BaseController {

    private final IWcsIntfOutlogService iWcsIntfOutlogService;

    /**
     * 查询Outbound接口日志列表
     */
    @SaCheckPermission("wcs:intfOutlog:list")
    @GetMapping("/list")
    public TableDataInfo<WcsIntfOutlogVo> list(WcsIntfOutlogBo bo, PageQuery pageQuery) {
        return iWcsIntfOutlogService.selectVoPage(bo, pageQuery);
    }

    /**
     * 导出Outbound接口日志列表
     */
    @SaCheckPermission("wcs:intfOutlog:export")
    @Log(title = "Outbound接口日志", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(WcsIntfOutlogBo bo, HttpServletResponse response) {
        List<WcsIntfOutlogVo> list = iWcsIntfOutlogService.selectVoList(bo);
        ExcelUtil.exportExcel(list, "Outbound接口日志", WcsIntfOutlogVo.class, response);
    }

    /**
     * 获取Outbound接口日志详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("wcs:intfOutlog:query")
    @GetMapping("/{id}")
    public R<WcsIntfOutlogVo> getInfo(@NotNull(message = "主键不能为空")
                                      @PathVariable Long id) {
        return R.ok(iWcsIntfOutlogService.selectVoById(id));
    }

    /**
     * 新增Outbound接口日志
     */
    @SaCheckPermission("wcs:intfOutlog:add")
    @Log(title = "Outbound接口日志", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody WcsIntfOutlogBo bo) {
        return toAjax(iWcsIntfOutlogService.insertByBo(bo));
    }

    /**
     * 修改Outbound接口日志
     */
    @SaCheckPermission("wcs:intfOutlog:edit")
    @Log(title = "Outbound接口日志", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody WcsIntfOutlogBo bo) {
        return toAjax(iWcsIntfOutlogService.updateByBo(bo));
    }

    /**
     * 删除Outbound接口日志
     *
     * @param ids 主键串
     */
    @SaCheckPermission("wcs:intfOutlog:remove")
    @Log(title = "Outbound接口日志", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空") @PathVariable Long[] ids) {
        return toAjax(iWcsIntfOutlogService.deleteWithValidByIds(Arrays.asList(ids)));
    }

    /**
     * 接口重试
     */
    @SaCheckPermission("wcs:intfOutlog:retry")
    @Log(title = "接口重试", businessType = BusinessType.OTHER)
    @RepeatSubmit()
    @PostMapping("/retry")
    public R<Boolean> retry(@RequestBody WcsIntfOutlogBo bo) {
        return R.ok(iWcsIntfOutlogService.retry(bo));
    }
}
